package com.javasvip.serviceuser.controller;

import com.javasvip.common.pojo.Token;
import com.javasvip.serviceuser.dao.AuthCodeDao;
import com.javasvip.serviceuser.service.CodeService;
import com.javasvip.serviceuser.service.TolenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    TolenService tolenService;
    @Autowired
    AuthCodeDao authCodeDao;
    @Autowired
    CodeService codeService;

    /**
     * 登录
     * @param email
     * @param password
     * @return
     */
    @GetMapping("/login/{email}/{password}")
    public Object login(@PathVariable String email,@PathVariable String password) {
        Token login = tolenService.login(email, password);
        System.out.println("登录用户数据"+login);
        return login;
    }

    /**
     * 注册
     * @return
     */
    @GetMapping("/register/{email}/{password}/{code}")
    public Object register(@PathVariable String email,@PathVariable String password,@PathVariable String code) {
        System.out.println(email+":"+password+":"+code);

        Integer verification = codeService.verification(email, code);
       if(verification==0){
           Token token=new Token();
           token.setEmail(email);
           token.setToken(password);
           tolenService.save(token);
           System.out.println("保存成功");
       }else{
           System.out.println("注册失败");
       }
        return verification;
    }



}
